import logging
import time

import pyautogui

from src.model import GuoFu
from src.utils import MouseUtils


def move_to(new_origin_coordinates, to_name, adjust_x=0, adjust_y=0):
    """
    1080*1920手机屏幕适配坐标
    """
    coordinates = {
        GuoFu.CoordinateNames.QIANG_HONG_BAO: (959, 731),
        GuoFu.CoordinateNames.YOU_HUA: (1203, 555),
        GuoFu.CoordinateNames.SHOU_HONG_BAO: (957, 726),
        GuoFu.CoordinateNames.JI_XU_XIN_SHANG: (1071, 759),
        GuoFu.CoordinateNames.GUANG_GAO_YE_ZUO_HUI_TUI: (731, 121),
        GuoFu.CoordinateNames.QIANG_HONG_BAO_ZUO_SHANG_JIAO: (684, 44),
        GuoFu.CoordinateNames.QIANG_HONG_BAO_YOU_XIA_JIAO: (1235, 1027),
    }
    return MouseUtils.move_to_new_origin(coordinates, GuoFu.CoordinateNames.QIANG_HONG_BAO, new_origin_coordinates, to_name, adjust_x=adjust_x, adjust_y=adjust_y)


def moveTo(x, y):
    pyautogui.moveTo(x, y)
    return x, y


def move_to_and_click(new_origin_coordinates, to_name, sleep=1):
    new_position = move_to(new_origin_coordinates, to_name)
    logging.info(f"移动到新坐标: {new_position}")
    if sleep > 0:
        time.sleep(sleep)
    pyautogui.click(new_position)
